#

| Chapter 7 Setting Your Shell Prompt |

## 7.5 Multiline Shell Prompts

Lots of people like lots of information in their prompts: hostname, directory name, history number, maybe username. Lots of people have spent lots of time trying to make their prompts short enough to fit across the screen and still leave room for typing a command longer than ls:

>     <elaineq@applefarm> [/usr/elaineq/projects/april/week4] 23 % ls

Even with fairly short prompts, if you look back at a screen after running a few commands, telling the data from the prompts can be a little tough (real terminals don't show user input in boldface, so I won't do it here either):

>     '\" DON'T BOLDFACE USER'S INPUT HERE, SO IT BLENDS TOGETHER LIKE REAL SCREEN:
>     <elaineq@applefarm> [~] 56% cd beta
>     <elaineq@applefarm> [~/beta] 57% which prog
>     /usr/tst/applefarm/bin/beta/prog
>     <elaineq@applefarm> [~/beta] 58% prog
>     61,102 units inventoried; 3142 to do
>     <elaineq@applefarm> [~/beta] 59%

One nice answer is to make a prompt that has more than one line. Here's part of a .cshrc file that sets a three-line prompt: one blank line, one line with the hostname and current directory, and a third with the history number and a percent sign:

    uname -n

    {..}
    set hostname=`uname -n`
    alias setprompt 'set prompt="\\
    ${hostname}:${cwd}\\
    \! % "'
    alias cd 'chdir \!* && setprompt'
    setprompt           # to set the initial prompt

The prompts look like this:

>     applefarm:/usr/elaineq/projects/april/week4
>     23 % prog | tee /dev/tty | mail -s "prog results" bigboss@corpoffice
>     61,102 units inventoried; 3142 to do

>     applefarm:/usr/elaineq/projects/april/week4
>     24 % cd ~/beta

>     applefarm:/usr/elaineq/beta
>     25 % prog | mail joanne

The blank lines separate each command - though you may want to save space by omitting them. For example, Mike Sierra (here at O'Reilly & Associates) uses a row of asterisks:

>     ***** 23 *** <mike@mymac> *** /home/mike/calendar *****
>     % cd September
>     ***** 24 *** <mike@mymac> *** /home/mike/calendar/September *****
>     %

You don't need a multiline prompt-setting command to get a newline into bash prompts. Just put a `\n` (which stands for a newline character) anywhere you want the prompt to break to a new line.

What I like best about multiline prompts is that you get a lot of information but have the whole screen width for typing. Of course, you can put different information in the prompt than I've shown here. The important idea is: if you want more information and need room to type, try a multiline prompt.

- JP

7.4 Faster Prompt Setting with Built-Ins |  | 7.6 Session Information in Your Terminal's Status Line